﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Web.Profile;
using System.Web.Security;
using ParieurPro.DAL;
using ParieurPro.DAL.DatabaseModel;

namespace MyBet.Web.Services
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class JoinService
    {
        [OperationContract]
        public List<CustomContestObject> GetAllowedContest(string userEmail)
        { 
            List<CustomContestObject> returnList;
            using (MyBetDBEntities dbContext = new MyBetDBEntities())
            {
               returnList = CustomContestObject.GetAllowedContests(dbContext, userEmail);
            }
            return returnList;
        }

        [OperationContract]
        public CustomContestObject.JoinContestStatus JoinContest(Guid userId, string contestName, string contestPassword)
        {
            CustomContestObject.JoinContestStatus returnValue;
            using (MyBetDBEntities dbContext = new MyBetDBEntities())
            {
                returnValue = CustomContestObject.JoinCustomContest(dbContext, userId, contestName, contestPassword);
            }
            return returnValue;
        }

        [OperationContract]
        public CustomContestObject.DisjoinContestStatus DisjoinContest(Guid userId, int customContestId)
        {
            CustomContestObject.DisjoinContestStatus returnValue;
            using (MyBetDBEntities dbContext = new MyBetDBEntities())
            {
                returnValue = CustomContestObject.DisjoinCustomContest(dbContext, userId, customContestId);
            }
            return returnValue;
        }

        [OperationContract]
        public List<CustomContestObject> GetSubscription(Guid userId, out ParieurProFault myFault)
        {
            List<CustomContestObject> returnValue =new List<CustomContestObject>();
            myFault = null;
            using (MyBetDBEntities dbContext = new MyBetDBEntities())
            {
                returnValue = UserObject.GetSubscriptions(dbContext, userId);
            }
            return returnValue;
        }

        [OperationContract]
        public bool SetDefaultCustomContest(Guid userId, int customContestId, out ParieurProFault myFault)
        {
            bool returnValue = false;
            myFault = null;
            using (MyBetDBEntities dbContext = new MyBetDBEntities())
            {
                returnValue = UserObject.SetDefaultCustomContest(dbContext, userId, customContestId);
            }
            return returnValue;
        }


    }
}
